// Do file that puts together the Minnesota data to be used for the papr "Persistent Inequalities"

use "E:\ProjData\AdoptionStudy\MnData\MNSibs.dta", clear

*Generate parental turnout indicators
egen vote_2010_PARENTS = rowmean(vote_2006_MOM vote_2006_DAD)
egen vote_2014_PARENTS = rowmean(vote_2006_MOM vote_2006_DAD vote_2010_MOM vote_2010_DAD)
egen vote_2018_PARENTS = rowmean(vote_2006_MOM vote_2006_DAD vote_2010_MOM vote_2010_DAD vote_2014_MOM vote_2014_DAD)

gen vote_midterm_PARENTS = vote_2010_PARENTS if ELECTION==2010
replace vote_midterm_PARENTS = vote_2014_PARENTS if ELECTION==2014
replace vote_midterm_PARENTS = vote_2018_PARENTS if ELECTION==2018


*2 indicators for stability in parental voting
*Variation in stability is due both to over time variation within parent
*and across parent variation at a specific time point
*2nd indicator: Herfindahl's index standardized to 0-1 range
egen parentconsistent = rowmean(vote_2006_MOM vote_2006_DAD vote_2010_MOM vote_2010_DAD vote_2014_MOM vote_2014_DAD vote_2018_MOM vote_2018_DAD)
replace parentconsistent = 1 if parentconsistent==0
replace parentconsistent = 0 if inrange(parentconsistent, 0.05, 0.95)
egen occ1 = rowmean(vote_2006_MOM vote_2006_DAD vote_2010_MOM vote_2010_DAD vote_2014_MOM vote_2014_DAD vote_2018_MOM vote_2018_DAD)
gen parentconsistentHI = -1*(1-(occ1^2+(1-occ1)^2))/0.5+1


*Save estimation dataset
gen kidfemale = MALE*-1+1
gen kidelectionage = ELECTION - BYR_CHILD - 18
keep if inrange(kidelectionage, 0, 32)

drop if ELECTION==2006 | ELECTION==2008 | ELECTION==2012 | ELECTION==2016

rename IDYRFAM famid
rename vote_CHILD turnoutkid
rename avg_BYR_PARENTS parentbyear
rename ELECTION electionyear
rename vote_midterm_PARENTS turnoutparentcum

keep famid turnoutkid kidfemale parentbyear parentconsistent parentconsistentHI electionyear kidelectionage turnoutparentcum RELATED
keep if turnoutkid!=.
gen sample = 4
gen kidelectionage01 = kidelectionage/32

save "E:\ProjData\AdoptionStudy\MnData\MNData.dta", replace

